﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site/QuanLyDuoc/QuanLyDuoc_OffCanvas.Master" AutoEventWireup="true" CodeBehind="PhieuNhapVatTu.aspx.cs" Inherits="HospitalManager.QuanLyDuoc.HeThongTaiChinh.ThanhToanHoaDon.PhieuNhapVatTu" %>

<%@ Register Src="../HeThongTaiChinh_LeftMenu.ascx" TagName="HeThongTaiChinh_LeftMenu" TagPrefix="uc1" %>

<%@ Register Src="../../HeThongNhapXuat/PhieuNhapVatTu/uc_ViewPhieu.ascx" TagName="uc_ViewPhieu" TagPrefix="uc2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(function () {
            $("#li_thanhtoanhoadon_phieunhapvattu").addClass("active");
            $("#li_hethongtaichinh").addClass("active");
            $("#ddlKho_Khoa").parent().find(".dropdown-toggle").focus();
            $("#txtTuNgay").data("DateTimePicker").setMaxDate($("#txtDenNgay").val());
            $("#txtDenNgay").data("DateTimePicker").setMinDate($("#txtTuNgay").val());
            $("#txtTuNgay").on("dp.change", function (e) {
                $("#txtDenNgay").data("DateTimePicker").setMinDate(e.date);
            });
            $("#txtDenNgay").on("dp.change", function (e) {
                $("#txtTuNgay").data("DateTimePicker").setMaxDate(e.date);
            });
            $("#txtDenNgay").bind("keydown", function (e) {
                if (e.which === 13) {
                    e.preventDefault();
                    $("#btnTimKiem").focus();
                }
            });
        });

        function validationform_Timkiem() {
            $("#txtTuNgay").rules("add", {
                required: true,
                messages: {
                    required: MsErrorEmpty
                }
            });
            $("#txtDenNgay").rules("add", {
                required: true,
                messages: {
                    required: MsErrorEmpty
                }
            });
        }

        function viewphieunhapvattu(tag_button) {
            var maphieunhap = $(tag_button).attr("maphieunhap");
            if (maphieunhap == "") return;
            var dataPhieuNhapVatTu = PhieuNhapVatTu_SelectById(maphieunhap);
            $("#txtSoChungTu_View").val(dataPhieuNhapVatTu[0].SoChungTu);
            (dataPhieuNhapVatTu[0].NgayChungTu == null || dataPhieuNhapVatTu[0].NgayChungTu == "")
                ? $("#txtNgayChungTu_View").val("")
                : $("#txtNgayChungTu_View").val(moment(dataPhieuNhapVatTu[0].NgayChungTu).format("DD-MM-YYYY"));
            $("#txtKhoNhap_View").val(dataPhieuNhapVatTu[0].TenKho);
            $("#txtNhaCungCap_View").val(dataPhieuNhapVatTu[0].TenNhaCungCap);
            (dataPhieuNhapVatTu[0].NgayGiao == null || dataPhieuNhapVatTu[0].NgayGiao == "")
                ? $("#txtNgayGiao_View").val("")
                : $("#txtNgayGiao_View").val(moment(dataPhieuNhapVatTu[0].NgayGiao).format("DD-MM-YYYY"));
            $("#txtNguoiGiao_View").val(dataPhieuNhapVatTu[0].NguoiGiao);
            $("#txtNguoiNhan_View").val(dataPhieuNhapVatTu[0].NguoiNhan);
            $("#txtThue_View").val(dataPhieuNhapVatTu[0].GT_Thue);
            $("#txtGhiChu_View").val(dataPhieuNhapVatTu[0].DienGiai);
            // Thông tin thuốc-vật tư
            $("#tb_phieunhapvattu_chitiet_view").bootstrapTable("destroy");
            $("#tb_phieunhapvattu_chitiet_view").bootstrapTable({
                classes: "table table-condensed",
                cache: false,
                pagination: true,
                pageList: [],
                search: true,
                searchAlign: "right",
                formatShowingRows: function () {
                    return "";
                },
                method: "post",
                sidePagination: "server",
                url: "/Webservice/QuanLyDuoc/HeThongNhapXuat/wsPhieuNhapVatTu.asmx/PhieuNhapVatTu_ChiTiet_SelectByMaPhieuNhap",
                queryParams: function (p) {
                    return {
                        maphieunhap: maphieunhap,
                        textsearch: $(".search input").val(),
                        offset: p.offset,
                        limit: p.limit
                    };
                },
                responseHandler: function (res) {
                    var data = $.parseJSON(res.d);
                    return {
                        total: data.Table1[0].ToTalRow,
                        rows: data.Table
                    };
                },
                columns: [
                    {
                        checkbox: true
                    }, {
                        field: "RowNumber",
                        title: "STT",
                        align: "right"
                    }, {
                        field: "TenVatTu",
                        title: "Tên vật tư"
                    }, {
                        field: "TenDonVi",
                        title: "Đơn vị",
                        align: "center"
                    }, {
                        field: "DonGia",
                        title: "Đơn giá",
                        align: "right",
                        formatter: function (value) {
                            return $.number(value, 0, ".", ",");
                        }
                    }, {
                        field: "SoLuong",
                        title: "Số lượng",
                        align: "right",
                        formatter: function (value) {
                            return $.number(value, 0, ".", ",");
                        }
                    }, {
                        field: "LoSanXuat",
                        title: "Lô sản xuất",
                        align: "center"
                    }, {
                        field: "NgaySanXuat",
                        title: "Ngày sản xuất",
                        align: "center"
                    }, {
                        field: "HanSuDung",
                        title: "Hạn sử dụng",
                        align: "center"
                    }
                ]
            });
            $("#div_phieunhapvattu_view").modal("show");
        }

        var PhieuNhapVatTu = {
            ArrJson: [],
            PhieuNhapVatTu_SelectById: function (maphieunhap) {
                $.ajax({
                    type: "POST",
                    url: "/Webservice/QuanLyDuoc/HeThongNhapXuat/wsPhieuNhapVatTu.asmx/PhieuNhapVatTu_SelectById",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: "{'maphieunhap': '" + maphieunhap + "'}",
                    async: false,
                    success: function (n) {
                        if (n.d != null || n.d != undefined) {
                            PhieuNhapVatTu.ArrJson = $.parseJSON(n.d);
                        }
                    },
                    error: function () {
                        bootbox.alert("Có lỗi xảy ra, vui lòng thử lại");
                    }
                });
                return PhieuNhapVatTu.ArrJson;
            }
        };
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="LeftContent" runat="server">
    <uc1:HeThongTaiChinh_LeftMenu ID="HeThongTaiChinh_LeftMenu2" runat="server" />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div class="row">
        <div class="form-horizontal">
            <div class="col-xs-3 col-md-3">
                <asp:DropDownList ID="ddlKho_Khoa" runat="server" ClientIDMode="Static" data-live-search="true">
                </asp:DropDownList>
            </div>
            <div class="col-xs-4 col-md-4">
                <div class="input-group">
                    <span class="input-group-addon">Từ ngày</span>
                    <asp:TextBox ID="txtTuNgay" ClientIDMode="Static" runat="server" CssClass="form-control ipdate dateFormat"
                        placeholder="Từ ngày"></asp:TextBox>
                    <span class="input-group-addon" style="border-right: 0;">đến ngày</span>
                    <asp:TextBox ID="txtDenNgay" ClientIDMode="Static" runat="server" CssClass="form-control ipdate dateFormat"
                        placeholder="Đến ngày"></asp:TextBox>
                </div>
            </div>
            <div class="col-xs-2 col-md-2">
                <asp:Button ID="btnTimKiem" ClientIDMode="Static" runat="server" Text="Tìm kiếm" CssClass="btn btn-default"
                    OnClientClick="validationform_Timkiem()" OnClick="btnTimKiem_Click" />
            </div>
        </div>
    </div>
    <div class="row" style="margin-top: 10px;">
        <div class="col-md-12">
            <div class="form-group table-responsive">
                <asp:GridView ID="gvPhieuNhapVatTu" runat="server" AutoGenerateColumns="False" Width="100%" OnRowDataBound="gvPhieuNhapVatTu_RowDataBound"
                    CssClass="table table-bordered table-condensed" DataKeyNames="MaPhieuNhap" ShowHeaderWhenEmpty="True">
                    <EmptyDataTemplate>
                        <div class="row" style="text-align: center;">
                            <asp:Label ID="Label1" runat="server">Không tìm thấy dữ liệu</asp:Label>
                        </div>
                    </EmptyDataTemplate>
                    <Columns>
                        <asp:BoundField DataField="NgayGiao" HeaderText="Ngày giao" DataFormatString="{0:dd-MM-yyyy}">
                            <ItemStyle HorizontalAlign="Center"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField DataField="TenKho" HeaderText="Kho nhập"></asp:BoundField>
                        <asp:BoundField DataField="NguoiGiao" HeaderText="Người giao"></asp:BoundField>
                        <asp:BoundField DataField="NguoiNhan" HeaderText="Người nhận"></asp:BoundField>
                        <asp:BoundField DataField="TongTien" HeaderText="Tổng tiền" DataFormatString="{0:n0}">
                            <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField DataField="Thue" HeaderText="Thuế">
                            <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        </asp:BoundField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="btnViewPhieuNhapVatTu" ClientIDMode="Static" runat="server" ToolTip="Xem thông tin phiếu"
                                    CssClass="btn btn-success btn-sm" maphieunhap='<%# Eval("MaPhieuNhap") %>' OnClientClick="viewphieunhapvattu(this);" href="javascript:void(0)">
                                    <i class="glyphicon glyphicon-search"></i>
                                </asp:LinkButton>
                                <asp:LinkButton ID="btnDuyetPhieuNhapVatTu" ClientIDMode="Static" runat="server" ToolTip="Duyệt phiếu"
                                    CssClass="btn btn-info btn-sm" CommandArgument='<%# Eval("MaPhieuNhap") %>' OnClick="btnDuyetPhieuNhapVatTu_Click">
                                    <i class="glyphicon glyphicon-check"></i>
                                </asp:LinkButton>
                                <div class="btn-group dropup" id="">
                                    <asp:LinkButton ID="btnDropDownTraLaiPhieuNhapVatTu" runat="server" ToolTip="Trả lại phiếu"
                                        CssClass="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-expanded="false" OnClientClick="$('.dropdown-menu-form').find('input:text').val('');">
                                        <i class="glyphicon glyphicon-share"></i>
                                    </asp:LinkButton>
                                    <ul class="dropdown-menu dropdown-menu-right dropdown-menu-form" role="menu" style="width: 460px;">
                                        <li>
                                            <div class="col-xs-12 col-md-12" style="margin-top: 10px;">
                                                <div class="form-horizontal">
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">
                                                            Lý do</label>
                                                        <div class="col-sm-10">
                                                            <asp:TextBox ID="txtGhiChu" runat="server" CssClass="form-control"></asp:TextBox>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </li>
                                        <li>
                                            <div class="col-xs-12 col-md-12">
                                                <div class="form-horizontal">
                                                    <div class="form-group">
                                                        <div class="col-sm-offset-2 col-sm-10">
                                                            <asp:LinkButton ID="btnTraLaiPhieuNhapVatTu" runat="server" Text="Chấp nhận"
                                                                CssClass="btn btn-success" CommandArgument='<%# Eval("MaPhieuNhap") %>'
                                                                OnClick="btnTraLaiPhieuNhapVatTu_Click">
                                                            </asp:LinkButton>
                                                            <asp:LinkButton ID="btnThoat" runat="server" Text="Thoát" CssClass="btn btn-danger"
                                                                OnClientClick="$('.dropdown-menu-form').parent().removeClass('open');" href="javascript:void(0)"></asp:LinkButton>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="10%" />
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
        </div>
        <div class="col-md-6" style="text-align: right;">
            <asp:DataList RepeatDirection="Horizontal" runat="server" ID="dlPager" OnItemCommand="dlPager_ItemCommand"
                CssClass="tbPage">
                <ItemTemplate>
                    <asp:LinkButton Enabled='<%#Eval("Enabled") %>' runat="server" ID="lnkPageNo" Text='<%#Eval("Text") %>'
                        CommandArgument='<%#Eval("Value") %>' CommandName="PageNo"></asp:LinkButton>
                </ItemTemplate>
            </asp:DataList>
        </div>
    </div>
    <asp:HiddenField ID="hfPageIndex" runat="server" Value="1" />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="FormContent" runat="server">
    <div id="div_phieunhapvattu_view" class="modal fade" tabindex="-1" role="dialog" data-backdrop="static"
        data-width="98%" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" style="line-height: 1;">
                        <span>&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">Phiếu nhập vật tư</h4>
                </div>
                <div class="modal-body modal-fullheight">
                    <uc2:uc_ViewPhieu ID="uc_ViewPhieu1" runat="server" />
                </div>
            </div>
        </div>
    </div>
</asp:Content>
